import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {Setting} from '../../../public/setting/setting';
import {CodeType} from '../../../public/setting/enums';

@Component({
  selector: 'app-bread-crumb',
  templateUrl: './bread-crumb.component.html',
  styleUrls: ['./bread-crumb.component.scss']
})
export class BreadCrumbComponent implements OnInit, OnChanges {
  @Input() furtherData: any = {};
  @Input() curFilePath: string;
  @Input() curFileType: string;
  public activeEditorOriginPathList: Array<string> = [];
  public codeTypes = CodeType;

  constructor() {
  }

  ngOnChanges(changes: SimpleChanges): void {
    if (changes && changes['curFilePath']) {
      if (this.curFilePath) { this.getFilePath(); }
    }
  }

  ngOnInit() {
  }

  getFilePath() {
    const path = this.curFilePath.indexOf('/') === 0 ? this.curFilePath.substring(1) : this.curFilePath;
    this.activeEditorOriginPathList = path.split('/');
  }

  openInFurther() {
    window.open(`${Setting.furtherFrontendUrl}/projects/${this.furtherData.projectId}/v${this.furtherData.number}`);
  }

}
